import org.cicd.devops.*
import org.cicd.enums.PipelineType
import org.cicd.utils.utils
import org.cicd.utils.log

/**
 * 构建代码上传私服
 * <p>
 *   适用场景，构建公共包
 * </p>
 * @param paramMap
 * @return
 */
def call(paramMap) {
    milestone(ordinal: 1)
    script {
        properties([buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '5')), pipelineTriggers([])])
    }

    def pomDir = paramMap.pomDir
    def mvnCommand = paramMap.mvnCommand
    def buildType = paramMap.buildType
    def branchName = "${env.BRANCH_NAME}"
    env.branchName = branchName
    //如果不传入mvnCommand，则执行默认mvn命令
    def executeMvnCommand = ""

    def build_user = getBuildUser()

    println "pomDir:${pomDir}"
    println "mvnCommand:${mvnCommand}"
    println "buildType:${buildType}"
    println "branchName:${branchName}"
    println "executeMvnCommand:${executeMvnCommand}"
    println "构建人:${build_user}"

    echo "并行构建检查(不允许同一项目同一分支同时多次构建）..."
    def isStop = "${BUILD_NUMBER}" == "1" ? false : Jenkins.instance.getItemByFullName("${JOB_NAME}").getBuilds()[1..-1].any { it.isBuilding() }
    if (!isStop)
        echo "并行构建检查通过"
    else {
        echo "有同类其他job在构建，该job停止构建!"
        sh "exit 1"
    }

    switch (buildType) {
        case 'mvn':
            jarBuildPipline(paramMap)
            break;
        case 'npm':
            break;
        default:
            println("无法识别项目类型");
            break;
    }

}

return this